class Solution(object):
    def nextGreatestLetter(self, letters, target):
        """
        :type letters: List[str]
        :type target: str
        :rtype: str
        """
        l = -1
        h = len(letters)
        while l + 1 != h:
            mid = l + (h - l) / 2
            if letters[mid] <= target:
                l = mid
            else:
                h = mid
        if h == len(letters):
            return letters[0]
        else:
            return letters[h]
